//
//  ICNetworkState.swift
//  ScanMan
//
//  Created by topnet on 2022/9/22.
//

import UIKit
import Alamofire

enum NetworkState {
    case wifi, mobile, none
}

class ICNetworkState: NSObject {
    static let shared = ICNetworkState()
    private override init() {
        super.init()
        manager = NetworkReachabilityManager(host: "www.apple.com")
    }
    var manager: NetworkReachabilityManager?
    func listen(completion: @escaping ((NetworkState)->())) {
        manager?.startListening { status in
            
            if status == .reachable(.ethernetOrWiFi) { //WIFI
                completion(.wifi)
            } else if status == .reachable(.cellular) { // 蜂窝网络
                completion(.mobile)
            } else { // 其他
                completion(.none)
            }
        }
    }
}
